---
layout: api
title: "v2.0.0 JavaScript Library: L.GeoJson"
categories: api
version: v2.0.0
permalink: /api/v2.0.0/l-geojson/
---
<h2 id="geojson">GeoJson</h2>

<p>Represents a <a href="http://geojson.org/geojson-spec.html">GeoJSON</a> layer. Allows you to parse GeoJSON data and display it on the map. Extends <a href="/mapbox.js/api/v2.0.0/l-featuregroup">FeatureGroup</a>.</p>

<pre><code class="javascript">L.geoJson(data, {
	style: function (feature) {
return {color: feature.properties.color};
	},
	onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.description);
	}
}).addTo(map);</code></pre>

<p>Each feature layer created by it gets a <code>feature</code> property that links to the GeoJSON feature data the layer was created from (so that you can access its properties later).</p>

<h3>Creation</h3>

<table data-id='geojson'>
	<tr>
<th>Factory</th>
<th>Description</th>
	</tr>
	<tr>
<td><code><b>L.geoJson</b>(
<nobr>&lt;Object&gt; <i>geojson?</i></nobr>,
<nobr>&lt;<a href="/mapbox.js/api/v2.0.0/l-geojson">GeoJSON options</a>&gt; <i>options?</i> )</nobr>
</code></td>

<td>Creates a GeoJSON layer. Optionally accepts an object in <a href="http://geojson.org/geojson-spec.html">GeoJSON format</a> to display on the map (you can alternatively add it later with <code>addData</code> method) and an options object.</td>
	</tr>
</table>

<h3 id="geojson-options">Options</h3>

<table data-id='geojson'>
	<tr>
<th>Option</th>
<th>Description</th>
	</tr>
	<tr id="geojson-pointtolayer">
<td><code><b>pointToLayer</b>(
<nobr>&lt;GeoJSON&gt; <i>featureData</i></nobr>,
<nobr>&lt;<a href="/mapbox.js/api/v2.0.0/l-latlng">LatLng</a>&gt; <i>latlng</i> )</nobr>
</code></td>

<td>Function that will be used for creating layers for GeoJSON points (if not specified, simple markers will be created).</td>
	</tr>
	<tr id="geojson-style">
<td><code><b>style</b>(
<nobr>&lt;GeoJSON&gt; <i>featureData</i> )</nobr>
</code></td>

<td>Function that will be used to get style options for vector layers created for GeoJSON features.</td>
	</tr>
	<tr id="geojson-oneachfeature">
<td><code><b>onEachFeature</b>(
<nobr>&lt;GeoJSON&gt; <i>featureData</i></nobr>,
<nobr>&lt;<a href="/mapbox.js/api/v2.0.0/l-ilayer">ILayer</a>&gt; <i>layer</i> )</nobr>
</code></td>

<td>Function that will be called on each created feature layer. Useful for attaching events and popups to features.</td>
	</tr>
	<tr id="geojson-filter">
<td><code><b>filter</b>(
<nobr>&lt;GeoJSON&gt; <i>featureData</i></nobr>,
<nobr>&lt;<a href="/mapbox.js/api/v2.0.0/l-ilayer">ILayer</a>&gt; <i>layer</i> )</nobr>
</code></td>

<td>Function that will be used to decide whether to show a feature or not.</td>
	</tr>
	<tr id="geojson-coordstolatlng">
<td><code><b>coordsToLatLng</b>(
<nobr>&lt;Array&gt; <i>coords</i></nobr> )</nobr>
</code></td>

<td>Function that will be used for converting GeoJSON coordinates to <a href="/mapbox.js/api/v2.0.0/l-latlng">LatLng</a> points (if not specified, coords will be assumed to be WGS84 &mdash; standard <code>[longitude, latitude]</code> values in degrees).</td>
	</tr>
</table>

<p>Additionally accepts all <a href="/mapbox.js/api/v2.0.0/l-path">Path options</a> for polylines and polygons.</p>

<h3>Methods</h3>

<table data-id='geojson'>
	<tr>
<th class="width250">Method</th>
<th class="minwidth">Returns</th>
<th>Description</th>
	</tr>
	<tr>
<td><code><b>addData</b>(
<nobr>&lt;GeoJSON&gt; <i>data</i> )</nobr>
</code></td>

<td><code>this</code></td>
<td>Adds a GeoJSON object to the layer.</td>
	</tr>
	<tr id="geojson-setstyle">
<td><code><b>setStyle</b>(
<nobr>&lt;Function&gt; <i><a href="/mapbox.js/api/v2.0.0/l-geojson">style</a></i> )</nobr>
</code></td>

<td><code><span class="keyword">this</span></code></td>
<td>Changes styles of GeoJSON vector layers with the given style function.</td>
	</tr>
	<tr id="geojson-resetstyle">
<td><code><b>resetStyle</b>(
<nobr>&lt;<a href="/mapbox.js/api/v2.0.0/l-path">Path</a>&gt; <i>layer</i> )</nobr>
</code></td>

<td><code><span class="keyword">this</span></code></td>
<td>Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events.</td>
	</tr>
</table>

<h3>Static methods</h3>

<table data-id='geojson'>
	<tr>
<th>Method</th>
<th>Returns</th>
<th>Description</th>
	</tr>
	<tr>
<td><code><b>geometryToLayer</b>(
<nobr>&lt;GeoJSON&gt; <i>featureData</i></nobr>,
<nobr>&lt;<a href="/mapbox.js/api/v2.0.0/l-geojson">Function</a>&gt; <i>pointToLayer?</i> )</nobr>
</code></td>

<td><code><a href="/mapbox.js/api/v2.0.0/l-ilayer">ILayer</a></code></td>
<td>Creates a layer from a given GeoJSON feature.</td>
	</tr>
	<tr>
<td><code><b>coordsToLatLng</b>(
<nobr>&lt;Array&gt; <i>coords</i></nobr>,
<nobr>&lt;Boolean&gt; <i>reverse?</i> )</nobr>
</code></td>

<td><code><a href="/mapbox.js/api/v2.0.0/l-latlng">LatLng</a></code></td>
<td>Creates a LatLng object from an array of 2 numbers (latitude, longitude) used in GeoJSON for points. If <code>reverse</code> is set to <code><span class="literal">true</span></code>, the numbers will be interpreted as (longitude, latitude).</td>
	</tr>
	<tr>
<td><code><b>coordsToLatLngs</b>(
<nobr>&lt;Array&gt; <i>coords</i></nobr>,
<nobr>&lt;Number&gt; <i>levelsDeep?</i></nobr>,
<nobr>&lt;Boolean&gt; <i>reverse?</i> )</nobr>
</code></td>

<td><code>Array</code></td>
<td>Creates a multidimensional array of LatLng objects from a GeoJSON coordinates array. <code>levelsDeep</code> specifies the nesting level (0 is for an array of points, 1 for an array of arrays of points, etc., 0 by default). If <code>reverse</code> is set to <code><span class="literal">true</span></code>, the numbers will be interpreted as (longitude, latitude).</td>
	</tr>
</table>



